%{
    This file is part of StemCellQC, a video bioinformatics software
    toolkit for analysis of phase contrast microscopy videos.
    Copyright 2013-2015 Vincent On. [vincenton001-at-gmail.com]

    StemCellQC is free software: you can redistribute it and/or 
    modify it under the terms of the GNU General Public License as 
    published by the Free Software Foundation, either version 3 of the 
    License, or (at your option) any later version.

    StemCellQC is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with StemCellQC.  If not, see <http://www.gnu.org/licenses/>.
%}

function varargout = plot_gui(varargin)
% PLOT_GUI MATLAB code for plot_gui.fig
%      PLOT_GUI, by itself, creates a new PLOT_GUI or raises the existing
%      singleton*.
%
%      H = PLOT_GUI returns the handle to a new PLOT_GUI or the handle to
%      the existing singleton*.
%
%      PLOT_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in PLOT_GUI.M with the given input arguments.
%
%      PLOT_GUI('Property','Value',...) creates a new PLOT_GUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before plot_gui_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to plot_gui_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help plot_gui

% Last Modified by GUIDE v2.5 02-Feb-2015 21:41:11

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @plot_gui_OpeningFcn, ...
    'gui_OutputFcn',  @plot_gui_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before plot_gui is made visible.
function plot_gui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to plot_gui (see VARARGIN)

% Choose default command line output for plot_gui
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes plot_gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = plot_gui_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on selection change in feat_menu.
function feat_menu_Callback(hObject, eventdata, handles)
% hObject    handle to feat_menu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

group = cell(1);
for i = 1 : 7
    group{ i } = eval( ['get( handles.group' num2str(i) ', ''string'' )']);
    group{ i } = eval(['[' group{ i } ']']);
end

%acquire slope properties from GUI
average = get( handles.Mov_avg_check, 'Value');
norm1st = get( handles.norm1st_check, 'Value');
plot_slope = get( handles.slope_check, 'Value');
offset_val = str2double( get( handles.offset_box , 'String' ) );
multi_val = str2double( get( handles.multiplier_box , 'String' ) );

%load and modify features
data = handles.avg_data;
[N_tp, N_feats, N_samples] = size( data );
feat_num = get( handles.feat_menu, 'Value');

data = data * multi_val + offset_val;   %offset and multiply


if plot_slope == 1 %convert data into slopes for plot
    temp_data = zeros( N_tp, N_feats, N_samples );
    for i = 1 : N_samples
        for j = 2 : N_tp
            temp_data( j, : ,i ) = (data( j, :, i ) - data( j - 1, :, i )) / 2;
        end
    end
    data = temp_data;
    clear temp_data
end

n_frames = str2double( get( handles.Avg_Interval , 'String' ) );
interval = round(n_frames/2);
for i = 1 : N_samples
    %calculate moving average
    if average == 1
        for j = 1:length(data(:,1,1))
            indices = j - interval : j + interval;
            indices( indices < 1 ) = [];
            indices( indices > length( data( :,1,1 ) ) ) = [];
            
            avg_data( j,:,i ) = mean( data( indices,:,i ) );
        end
    end
    
    %normalize data to first time point
    if norm1st == 1
        for j = 1 : length( data( 1, :, 1 ))
            if average == 1
                norm1st_data( :, j, i ) = avg_data( :, j, i ) / avg_data( 1, j, i );
            else
                norm1st_data( :, j, i ) = data( :, j, i ) / data( 1, j, i );
            end
        end
    end
end

%reshape data to plot
feat = zeros( N_samples, N_tp );
for i = 1 : N_samples
    if norm1st == 1
        feat( i, : ) = norm1st_data ( :, feat_num, i )';
    elseif average == 1
        feat( i, : ) = avg_data( :, feat_num, i )';
    else
        feat( i, : ) = data( :, feat_num, i )';
    end
end

%plot figure
figure('MenuBar', 'figure', 'Toolbar', 'figure');
plotedit on
for i = 1 : length( group )
    %plot if group is not empty
    if ~isempty( group{i} )
        feat_temp = feat( group{i}, : );
        
        color = eval(['get( handles.group' num2str(i) '_color ,''Value'' )']);
        
        switch color
            case 1
                color = 'g';
            case 2
                color = 'b';
            case 3
                color = 'r';
            case 4
                color = 'y';
            case 5
                color = 'c';
            case 6
                color = 'm';
            case 7
                color = 'k';
        end
        
        if numel( group{ i }) == 1
            x = [1:size(feat_temp)]';
            plot(feat_temp,color,'LineWidth',2);
        else
            plotWithShadeColor( feat_temp, color );
        end
    end
    hold on
end
plotedit on

%load plot properties
max_hours = str2double(get( handles.time_box ,'string'));
xlim([0 N_tp]);
set(gca, 'XTick', round([0 : N_tp / 9 : N_tp] ));
set(gca, 'XTickLabel', round([0 : max_hours / 9 : max_hours] ));
xlabel('Time (hours)')

unit_change = norm1st || plot_slope || offset_val ~= 0 || multi_val ~= 1;
switch feat_num
    case 1 %Area
        title('Area')
        ylabel('Pixels')
    case 2 %Perimeter
        title('Perimeter')
        ylabel('Pixels')
    case 3 %Centroid X
        title('Centroid X')
        ylabel('Pixels')
    case 4 %Centroid Y
        title('Centroid Y')
        ylabel('Pixels')
    case 5 %Extent
        title('Extent')
        
        if unit_change == 1
            ylabel('No Units')
        else
            ylabel('No Units (0 - 1)')
        end
    case 6 %Solidity
        title('Solidity')
        
        if unit_change == 1
            ylabel('No Units')
        else
            ylabel('No Units (0 - 1)')
        end
    case 7 %Orientation
        title('Orientation')
        ylabel('Degrees')
    case 8 %Major Axis
        title('Major Axis Length')
        ylabel('Pixels')
    case 9 %Minor Axis
        title('Minor Axis Length')
        ylabel('Pixels')
    case 10 %Eccentricity
        title('Eccentricity')
        
        if unit_change == 1
            ylabel('No Units')
        else
            ylabel('No Units (0 - 1)')
        end
    case 11 %Min Radius
        title('Minimum Radius')
        ylabel('Pixels')
    case 12 %Max Radius
        title('Maximum Radius')
        ylabel('Pixels')
    case 13 %Avg Radius
        title('Average Radius')
        ylabel('Pixels')
    case 14 %Avg Intensity
        title('Average Intensity')
        
        if unit_change == 1
            ylabel('No Units')
        else
            ylabel('No Units (0 - 255)')
        end
    case 15 %Max Intensity
        title('Maximum Intensity')
        
        if unit_change == 1
            ylabel('No Units')
        else
            ylabel('No Units (0 - 255)')
        end
    case 16 %Min Intensity
        title('Minimum Intensity')
        
        if unit_change == 1
            ylabel('No Units')
        else
            ylabel('No Units (0 - 255)')
        end
    case 17 %Brightness Ratio
        title('Brightness Ratio')
        
        if unit_change == 1
            ylabel('No Units')
        else
            ylabel('No Units (0 - 1)')
        end
    case 18 %# of Protrusions
        title('Number of Protrusions')
        ylabel('Protrusions')
    case 19 %Protruding Area
        title('Protruding Area')
        
        if unit_change == 1
            ylabel('No Units')
        else
            ylabel('No Units (0 - 1)')
        end
    case 20 %Change in Area
        title('Change in Area')
        ylabel('Pixels')
    case 21 %Change in Perimeter
        title('Change in Perimeter')
        ylabel('Pixels')
    case 22 %Change in Centroid
        title('Change in Centroid')
        ylabel('Pixels')
    case 23 %MSD
        title('Mean Squared Displacement')
        ylabel('Pixels^2')
    case 24 %Total Distance Traveled
        title('Total Distance Traveled')
        ylabel('Pixels^2')
    case 25 %Total Displacement
        title('Total Displacement')
        ylabel('Pixels')
end

new_title = get( handles.title_box, 'string' );
if ~strcmp(new_title, 'Title')
    title( new_title );
end 
%legend 
g1_name = get( handles.group1_name, 'string' );
g2_name = get( handles.group2_name, 'string' );
g3_name = get( handles.group3_name, 'string' );
g4_name = get( handles.group4_name, 'string' );
g5_name = get( handles.group5_name, 'string' );
g6_name = get( handles.group6_name, 'string' );
g7_name = get( handles.group7_name, 'string' );
legend(g1_name,'',g2_name,'',g3_name,'',g4_name,'',g5_name,'',g6_name,'',g7_name,'');

% --- Executes during object creation, after setting all properties.
function equation_box_CreateFcn(hObject, eventdata, handles)
% hObject    handle to equation_box (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in equation_button.
function equation_button_Callback(hObject, eventdata, handles)
% hObject    handle to equation_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
group = cell(1);
for i = 1 : 7
    group{ i } = eval( ['get( handles.group' num2str(i) ', ''string'' )']);
    group{ i } = eval(['[' group{ i } ']']);
end

%acquire slope properties from GUI
average = get( handles.Mov_avg_check, 'Value');
norm1st = get( handles.norm1st_check, 'Value');
plot_slope = get( handles.slope_check, 'Value');
offset_val = str2double( get( handles.offset_box , 'String' ) );
multi_val = str2double( get( handles.multiplier_box , 'String' ) );
feat_equation = get( handles.equation_box, 'String'); 

%load and modify features
data = handles.avg_data;
[N_tp, N_feats, N_samples] = size( data );
feat_num = get( handles.feat_menu, 'Value');

data = data * multi_val + offset_val;   %offset and multiply


if plot_slope == 1 %convert data into slopes for plot
    temp_data = zeros( N_tp, N_feats, N_samples );
    for i = 1 : N_samples
        for j = 2 : N_tp
            temp_data( j, : ,i ) = (data( j, :, i ) - data( j - 1, :, i )) / 2;
        end
    end
    data = temp_data;
    clear temp_data
end

feat_temp = permute(data, [3 1 2]);
f = cell(1);
for i = 1 : N_feats
    f{i} = feat_temp(:,:,i);
end
feat_temp = eval(feat_equation);

n_frames = str2double( get( handles.Avg_Interval , 'String' ) );
interval = round(n_frames/2);

    %calculate moving average
    if average == 1
        for j = 1:length(data(:,1,1))
            indices = j - interval : j + interval;
            indices( indices < 1 ) = [];
            indices( indices > length( feat_temp( 1,: ) ) ) = [];
            
            avg_data( :,j ) = mean( feat_temp( :,indices ),2 );
        end
    end
    
    %normalize data to first time point
    if norm1st == 1
        for j = 1 : length( data(:,1,1))
            if average == 1
                norm1st_data( :, j ) = avg_data( :, j ) ./ avg_data( :,1 );
            else
                norm1st_data( :, j ) = feat_temp( :, j ) ./ feat_temp( :, 1 );
            end
        end
    end




    if norm1st == 1
        feat = norm1st_data;
    elseif average == 1
        feat = avg_data;
    else
        feat = feat_temp;
    end


%plot figure
figure('MenuBar', 'figure', 'Toolbar', 'figure');
plotedit on
for i = 1 : length( group )
    %plot if group is not empty
    if ~isempty( group{i} )
        feat_temp = feat( group{i}, : );
        
        color = eval(['get( handles.group' num2str(i) '_color ,''Value'' )']);
        
        switch color
            case 1
                color = 'g';
            case 2
                color = 'b';
            case 3
                color = 'r';
            case 4
                color = 'y';
            case 5
                color = 'c';
            case 6
                color = 'm';
            case 7
                color = 'k';
        end
        
        if numel( group{ i }) == 1
            x = [1:size(feat_temp)]';
            plot(feat_temp,color,'LineWidth',2);
        else
            plotWithShadeColor( feat_temp, color );
        end
    end
    hold on
end
plotedit on

%load plot properties
max_hours = str2double(get( handles.time_box ,'string'));
xlim([0 N_tp]);
set(gca, 'XTick', round([0 : N_tp / 9 : N_tp] ));
set(gca, 'XTickLabel', round([0 : max_hours / 9 : max_hours] ));
xlabel('Time (hours)')


new_title = get( handles.title_box, 'string' );
if ~strcmp(new_title, 'Title')
    title( new_title );
end 
%legend 
g1_name = get( handles.group1_name, 'string' );
g2_name = get( handles.group2_name, 'string' );
g3_name = get( handles.group3_name, 'string' );
g4_name = get( handles.group4_name, 'string' );
g5_name = get( handles.group5_name, 'string' );
g6_name = get( handles.group6_name, 'string' );
g7_name = get( handles.group7_name, 'string' );
legend(g1_name,'',g2_name,'',g3_name,'',g4_name,'',g5_name,'',g6_name,'',g7_name,'');




% Hints: contents = cellstr(get(hObject,'String')) returns feat_menu contents as cell array
%        contents{get(hObject,'Value')} returns selected item from feat_menu


% --- Executes during object creation, after setting all properties.
function feat_menu_CreateFcn(hObject, eventdata, handles)
% hObject    handle to feat_menu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in load_folder.
function load_folder_Callback(hObject, eventdata, handles)
% hObject    handle to load_folder (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%% load data and labels
% get the directory


folder_name = uigetdir;
pastDir = cd;
cd( folder_name );

% the list of files in the directory
list = dir('*.csv');
list = [list; dir('*.xls')];


%load all files in directory
hWaitbar = waitbar( 0, 'Loading data' );

files = cell(size(list,1),1);
for i=1:size(list,1)
    
    display( deblank( list(i).name ) ) ;
    files{i} = list(i).name;
    temp = xlsread( deblank( list(i).name ) );
    temp(isnan(temp)) = 0;
    
    %fix some bad data points
    for j = 2:(length(temp(:,1))-1)
        if temp(j,end) > 200
            if temp(j+1,end) > 200
                temp(j,:) = mean([temp(j-1,:); temp(j+1,:)]);
                temp(j,end) = pdist([temp(j-1,4:5); temp(j,4:5)]);
                temp(j+1,end) = pdist([temp(j,4:5); temp(j+1,4:5)]);
            end
        end
    end
    
    temp(:,1) = [];  %remove index column
    
    %Derive additional features
    temp = derive_features( temp );
    
    data(:,:,i) = temp;
    
    close( hWaitbar );
    
    hWaitbar = waitbar( i / size(list,1), ...
        'Loading data' );
    
end

close( hWaitbar );

cd( pastDir );

handles.avg_data = data;

set( handles.uitable1, 'data', files );

% Update handles structure
guidata(hObject, handles);







function time_box_Callback(hObject, eventdata, handles)
% hObject    handle to time_box (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of time_box as text
%        str2double(get(hObject,'String')) returns contents of time_box as a double


% --- Executes during object creation, after setting all properties.
function time_box_CreateFcn(hObject, eventdata, handles)
% hObject    handle to time_box (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Avg_Interval_Callback(hObject, eventdata, handles)
% hObject    handle to Avg_Interval (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Avg_Interval as text
%        str2double(get(hObject,'String')) returns contents of Avg_Interval as a double


% --- Executes during object creation, after setting all properties.
function Avg_Interval_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Avg_Interval (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in Mov_avg_check.
function Mov_avg_check_Callback(hObject, eventdata, handles)
% hObject    handle to Mov_avg_check (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of Mov_avg_check


% --- Executes on button press in norm1st_check.
function norm1st_check_Callback(hObject, eventdata, handles)
% hObject    handle to norm1st_check (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of norm1st_check



function group1_Callback(hObject, eventdata, handles)
% hObject    handle to group1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of group1 as text
%        str2double(get(hObject,'String')) returns contents of group1 as a double


% --- Executes during object creation, after setting all properties.
function group1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function group2_Callback(hObject, eventdata, handles)
% hObject    handle to group2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of group2 as text
%        str2double(get(hObject,'String')) returns contents of group2 as a double


% --- Executes during object creation, after setting all properties.
function group2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function group3_Callback(hObject, eventdata, handles)
% hObject    handle to group3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of group3 as text
%        str2double(get(hObject,'String')) returns contents of group3 as a double


% --- Executes during object creation, after setting all properties.
function group3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function group4_Callback(hObject, eventdata, handles)
% hObject    handle to group4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of group4 as text
%        str2double(get(hObject,'String')) returns contents of group4 as a double


% --- Executes during object creation, after setting all properties.
function group4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function group5_Callback(hObject, eventdata, handles)
% hObject    handle to group5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of group5 as text
%        str2double(get(hObject,'String')) returns contents of group5 as a double


% --- Executes during object creation, after setting all properties.
function group5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in group1_color.
function group1_color_Callback(hObject, eventdata, handles)
% hObject    handle to group1_color (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns group1_color contents as cell array
%        contents{get(hObject,'Value')} returns selected item from group1_color


% --- Executes during object creation, after setting all properties.
function group1_color_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group1_color (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in group2_color.
function group2_color_Callback(hObject, eventdata, handles)
% hObject    handle to group2_color (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns group2_color contents as cell array
%        contents{get(hObject,'Value')} returns selected item from group2_color


% --- Executes during object creation, after setting all properties.
function group2_color_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group2_color (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in group3_color.
function group3_color_Callback(hObject, eventdata, handles)
% hObject    handle to group3_color (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns group3_color contents as cell array
%        contents{get(hObject,'Value')} returns selected item from group3_color


% --- Executes during object creation, after setting all properties.
function group3_color_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group3_color (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in group4_color.
function group4_color_Callback(hObject, eventdata, handles)
% hObject    handle to group4_color (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns group4_color contents as cell array
%        contents{get(hObject,'Value')} returns selected item from group4_color


% --- Executes during object creation, after setting all properties.
function group4_color_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group4_color (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in group5_color.
function group5_color_Callback(hObject, eventdata, handles)
% hObject    handle to group5_color (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns group5_color contents as cell array
%        contents{get(hObject,'Value')} returns selected item from group5_color


% --- Executes during object creation, after setting all properties.
function group5_color_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group5_color (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function group1_name_Callback(hObject, eventdata, handles)
% hObject    handle to group1_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of group1_name as text
%        str2double(get(hObject,'String')) returns contents of group1_name as a double


% --- Executes during object creation, after setting all properties.
function group1_name_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group1_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function group2_name_Callback(hObject, eventdata, handles)
% hObject    handle to group2_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of group2_name as text
%        str2double(get(hObject,'String')) returns contents of group2_name as a double


% --- Executes during object creation, after setting all properties.
function group2_name_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group2_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function group3_name_Callback(hObject, eventdata, handles)
% hObject    handle to group3_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of group3_name as text
%        str2double(get(hObject,'String')) returns contents of group3_name as a double


% --- Executes during object creation, after setting all properties.
function group3_name_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group3_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function group4_name_Callback(hObject, eventdata, handles)
% hObject    handle to group4_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of group4_name as text
%        str2double(get(hObject,'String')) returns contents of group4_name as a double


% --- Executes during object creation, after setting all properties.
function group4_name_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group4_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function group5_name_Callback(hObject, eventdata, handles)
% hObject    handle to group5_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of group5_name as text
%        str2double(get(hObject,'String')) returns contents of group5_name as a double


% --- Executes during object creation, after setting all properties.
function group5_name_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group5_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function title_box_Callback(hObject, eventdata, handles)
% hObject    handle to title_box (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of title_box as text
%        str2double(get(hObject,'String')) returns contents of title_box as a double


% --- Executes during object creation, after setting all properties.
function title_box_CreateFcn(hObject, eventdata, handles)
% hObject    handle to title_box (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function offset_box_Callback(hObject, eventdata, handles)
% hObject    handle to offset_box (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of offset_box as text
%        str2double(get(hObject,'String')) returns contents of offset_box as a double


% --- Executes during object creation, after setting all properties.
function offset_box_CreateFcn(hObject, eventdata, handles)
% hObject    handle to offset_box (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function multiplier_box_Callback(hObject, eventdata, handles)
% hObject    handle to multiplier_box (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of multiplier_box as text
%        str2double(get(hObject,'String')) returns contents of multiplier_box as a double


% --- Executes during object creation, after setting all properties.
function multiplier_box_CreateFcn(hObject, eventdata, handles)
% hObject    handle to multiplier_box (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in slope_check.
function slope_check_Callback(hObject, eventdata, handles)
% hObject    handle to slope_check (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of slope_check



function group6_name_Callback(hObject, eventdata, handles)
% hObject    handle to group6_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of group6_name as text
%        str2double(get(hObject,'String')) returns contents of group6_name as a double


% --- Executes during object creation, after setting all properties.
function group6_name_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group6_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in group7_color.
function group7_color_Callback(hObject, eventdata, handles)
% hObject    handle to group7_color (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns group7_color contents as cell array
%        contents{get(hObject,'Value')} returns selected item from group7_color


% --- Executes during object creation, after setting all properties.
function group7_color_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group7_color (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in group6_color.
function group6_color_Callback(hObject, eventdata, handles)
% hObject    handle to group6_color (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns group6_color contents as cell array
%        contents{get(hObject,'Value')} returns selected item from group6_color


% --- Executes during object creation, after setting all properties.
function group6_color_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group6_color (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function group6_Callback(hObject, eventdata, handles)
% hObject    handle to group6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of group6 as text
%        str2double(get(hObject,'String')) returns contents of group6 as a double


% --- Executes during object creation, after setting all properties.
function group6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function group7_Callback(hObject, eventdata, handles)
% hObject    handle to group7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of group7 as text
%        str2double(get(hObject,'String')) returns contents of group7 as a double


% --- Executes during object creation, after setting all properties.
function group7_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function group7_name_Callback(hObject, eventdata, handles)
% hObject    handle to group7_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of group7_name as text
%        str2double(get(hObject,'String')) returns contents of group7_name as a double


% --- Executes during object creation, after setting all properties.
function group7_name_CreateFcn(hObject, eventdata, handles)
% hObject    handle to group7_name (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function equation_box_Callback(hObject, eventdata, handles)
% hObject    handle to equation_box (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of equation_box as text
%        str2double(get(hObject,'String')) returns contents of equation_box as a double
